package thread;

import model.AlertParameters;
import model.User;
import model.UserEventDetail;
import utils.msg.ComplexPollingRunnable;
import utils.msg.PollingQueryRunnable;

/**
 * 线程控制类
 * @author zhrb
 *
 */
public class ThreadController {

	//将所要发送的电话号码封装到smsParams中
	public static PollingQueryRunnable sendMsg(AlertParameters ap, SmsParameters smsParams){
        PollingQueryRunnable pq=new PollingQueryRunnable(ap,smsParams);
        Thread t1 = new Thread(pq);
        t1.start();
       // pq.stopPolling();//终止线程
        return pq;
	}
	
	/**
	 * 1.产生发送信息的Runnable对象PollingQueryRunnable，并启动线程运行该Runnable对象
	 * 2.返回该Runnable对象
	 * 3.将所要发送的电话号码、email统一封装到AlertParameters中，比较方便操作。
	 * 4.现在仅考虑单用户
	 * @param ap 所有参数对象，包括所要发送到的电话号码与邮箱
	 * @return
	 */
	public static PollingQueryRunnable sendMsg(AlertParameters ap){
		SmsParameters smsParams=new SmsParameters();
		smsParams.setApikey(JavaSmsApi.getAPIKEY());
		smsParams.setMobile(ap.getPhone());
		PollingQueryRunnable pq=new PollingQueryRunnable(ap,smsParams);
		Thread t1 = new Thread(pq);
		t1.start();
		// pq.stopPolling();//终止线程
		return pq;
	}
	
	public static ComplexPollingRunnable sendMsg(UserEventDetail userEventDetail, String sender){
		SmsParameters smsParams=new SmsParameters();
		smsParams.setApikey(JavaSmsApi.getAPIKEY());
		smsParams.setMobile(userEventDetail.getUser().getPhoneNumber());
		ComplexPollingRunnable cpr = new ComplexPollingRunnable(userEventDetail, sender, smsParams);
		Thread t1 = new Thread(cpr);
		t1.start();
		return cpr;
	}
	
	
	
}
